package com.example.observer.v4;

import lombok.Data;
import lombok.ToString;

import java.util.ArrayList;
import java.util.List;

public class Main {

    public static void main(String[] args) {
        Child child = Child.getInstance();
        
        child.wakeUp();
    }
}

@ToString
@Data
class WakeUpEvent{
    long time;
    String location;
    Child source;
    public WakeUpEvent(long time, String location,Child source) {
        this.time = time;
        this.location = location;
        this.source=source;
    }
}

class Child {
    private boolean cry=false;
    private List<Obs> obsList=new ArrayList<>();
    {
        obsList.add(new Dad());
    }

    public boolean isCry(){
        return cry;
    }

    public void wakeUp(){
        System.out.println("wuwuwuwu");
        child.cry=true;
        for (Obs obs : obsList) {
            obs.action(new WakeUpEvent(System.currentTimeMillis(),"bed",child));
        }
    }

    private static final Child child=new Child();

    private Child(){
    }

    public static Child getInstance(){
        return child;
    }
}

interface Obs{
    void action(WakeUpEvent wakeUpEvent);
}

class Dad implements Obs{
    public void handle(WakeUpEvent wakeUpEvent){
        System.out.println("wakeUpEvent = " + wakeUpEvent);
        System.out.println("dad handle");
    }

    @Override
    public void action(WakeUpEvent wakeUpEvent) {
        this.handle(wakeUpEvent);
    }
}
